<!--
 * @description  : 案件-运输信息-面单信息-关联物品列表
 * @descriptionDetail: 案件-运输信息-面单信息-关联物品列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-11 14:36:53
-->
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
			<view class="nav-right-icon">
				<view @tap="handlerSure">
					确定
				</view>
			</view>
		</theme-navbar>
		<!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		 <fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
		<me-table :i="0" :top="0" :index="0" :load-data="loadData" ref="mescrollItem0">
			<template #default="d">
				<view class="card">
					<u-row @tap="handlerSelectItem(d.data)">
						<u-col span="10">
							<related-list-info :itemInfo="d.data"></related-list-info>
						</u-col>
						<u-col span="2" style="text-align:right;">
							<u-icon name="checkbox-mark" color="#2979ff" size="38" style="margin-right: 10px;" v-if="selectedUids.includes(d.data.goodsDtlUuid)"></u-icon>
						</u-col>
					</u-row>
				</view>
			</template>
		</me-table>
	</view>
</template>

<script>
	import MeTable from '@/components/me-table.vue';
	import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
	import relatedListInfo from './relatedListInfo';
	import caseService from '@/service/case/case.service.js';
	import fabButton from '@/components/uni-fab.vue';
	export default {
		components: {
			MeTable,
			fabButton,
			relatedListInfo,
		},
		mixins: [MescrollMoreMixin, ],
		data() {
			return {
				keyword: "",
				selectedUids: [], // 选中项的ids
				selectedItems: [], // 选中项
				objInfo: {},
				defaultOrg: undefined,
				type: undefined,
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			};
		},
		onLoad(opt) {
			this.type = opt.caseUuid;
			let listInfo = this.getRouteParam()
			listInfo.filter(item => {
				this.selectedUids.push(item.goodsDtlUuid);
				this.selectedItems.push(item);
			})
		},
		methods: {
			setRightBtns() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight("确定", () => {
					// 添加日计划操作
					this.handlerSure();
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.handlerSure()
				}
			},
			// 选中
			handlerSelectItem(data) {
				let selectItems = this.selectedItems.filter(item => {
					return item.goodsDtlUuid == data.goodsDtlUuid
				})
				if (selectItems.length > 0) {
					this.selectedItems = this.selectedItems.filter(s => s.goodsDtlUuid != data.goodsDtlUuid);
					this.selectedUids = this.selectedUids.filter(i => i != data.goodsDtlUuid);
				} else {
					this.selectedItems.push(data);
					this.selectedUids.push(data.goodsDtlUuid);
				}
			},
			// 在线案件查询数据
			loadData(page) {
				return new Promise((resolve, reject) => {
					caseService.queryGoodsByCase(this.type).then(res => {
						if (res.success) {
							resolve({
								count: res.count,
								data: res.data,
							});
						} else {
							this.$u.toast(res.msg);
							resolve({
								count: 0,
								data: [],
							});
						}
					}).catch(e => {
						this.$u.toast('请求失败:' + e);
						resolve({
							count: 0,
							data: [],
						});
					});
				})
			},
			// 确定
			handlerSure() {
				this.backPrev({
					paramKey: 'refresh',
					param: this.selectedItems,
				})
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/style/common/rightMenu.scss";

	.page {
		padding: 0;
	}

	.u-page {
		padding-bottom: 100rpx;
	}
</style>
